package com.xiaomage.view.draw6

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Path
import android.view.MotionEvent
import android.view.View

/**
 * Created by Administrator on 2018/1/2.
 */
class MyView3(context: Context): View(context) {
    private var path= Path()
    override fun onTouchEvent(event: MotionEvent): Boolean {
        when(event.action){
            MotionEvent.ACTION_DOWN ->{
                path.moveTo(event.x,event.y)
                return true
            }
            MotionEvent.ACTION_MOVE ->{
                path.lineTo(event.x,event.y)
                postInvalidate()
            }
        }
        return super.onTouchEvent(event)
    }
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)

        val paint= Paint()
        paint.style= Paint.Style.STROKE
        paint.isAntiAlias=true
        paint.color= Color.RED

        canvas.drawPath(path,paint)
    }

    public fun reset(){
        path.reset()
        postInvalidate()
    }
}